function readpraat(filename,y)

%--------------------------------------------------------
% writepraat
%
% escreve texto no formato de saida cronologico de dados
% dos marcadores segmentados no Praat.
%
% sintaxe
%
% writepraat('caminho do arquivo',y)
% 
% Y e estrutura de saída do expan_process_file
%
% obs: y deve ser uma estruct.
%--------------------------------------------------------

tam = length(y.signal);
fs = y.fs;
onset = y.onsets;
offset = y.offsets;

% valores em segundos
tams = tam/fs;
onsets = onset./fs;
offsets = offset./fs;


fid = fopen(filename,'at');

fprintf(fid,'"Praat chronological TextGrid text file"\n');
fprintf(fid,'0 ');
fprintf(fid,num2str(tams));
fprintf(fid,'   ! Time domain.');
fprintf(fid,'\n');
fprintf(fid,'2   ! Number of tiers.');
fprintf(fid,'\n');
fprintf(fid,'"TextTier" "onset" 0 ');
fprintf(fid,num2str(tams));
fprintf(fid,'\n');
fprintf(fid,'"TextTier" "offset" 0 ');
fprintf(fid,num2str(tams));
fprintf(fid,'\n');
for i = 1:length(onset)
    fprintf(fid,'1 ');
    fprintf(fid,num2str(onsets(i)));
    fprintf(fid,'\n');
    fprintf(fid,'""\n');
    fprintf(fid,'2 ');
    fprintf(fid,num2str(offsets(i)));
    fprintf(fid,'\n');
    fprintf(fid,'""\n');
end 

fclose(fid);





